package model

import (
	"strconv"
	"time"

	"gitee.com/konyshe/gogo"
)

type LterPhoneInfo struct {
	TellNum   string `json:"tell_num"`
	Imsi      string `json:"imsi"`
	OnTime    string `json:"on_time"`
	PcapCount int    `json:"pcap_count"`
	LterAddr  string `json:"lter_addr"`
}

var (
	pLterPhoneInfoMap map[uint64]*LterPhoneInfo
)

func InitLterPhone() {
	if pLterPhoneInfoMap == nil {
		pLterPhoneInfoMap = make(map[uint64]*LterPhoneInfo)
	}
}

func UpLterPhoneInfo(tellNum uint64, lterAddr string, imsi uint64, len, pcapCount int) {
	tPcapCount := pcapCount

	item, ok := pLterPhoneInfoMap[tellNum]
	if ok {
		item.PcapCount += tPcapCount
		tPcapCount = item.PcapCount

	} else {
		pLterPhoneInfoMap[tellNum] = &LterPhoneInfo{
			strconv.FormatUint(tellNum, 10),
			strconv.FormatUint(imsi, 10),
			time.Now().Format("2006-01-02 15:04:05"),
			tPcapCount,
			lterAddr,
		}
	}

	gogo.LogInfoF("Lter: %s TellNum: %d IMSI: %d Len: %d PcapCount: %d", lterAddr, tellNum, imsi, len, tPcapCount)
}

func GetLterPhoneInfoListJSON() []*LterPhoneInfo {
	var lterList []*LterPhoneInfo
	for addr := range pLterPhoneInfoMap {
		lterList = append(lterList, pLterPhoneInfoMap[addr])
	}

	return lterList
}
